package com.utilities.regex;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public abstract class HttpParam {

    private static Matcher compileAndMatcher(String input, String regex) {
        Pattern compile = Pattern.compile(regex);
        return compile.matcher(input);
    }

    public static String resolveParam(String input,String name){
        String  regex="(?:^| |&)"+name+"=([^&]*)(?:&|$)";
        Matcher matcher = compileAndMatcher(input, regex);
        StringBuilder sb=new StringBuilder();
        while (matcher.find()){
            sb.append(matcher.group(1)).append(" ");
        }
        sb.deleteCharAt(sb.length()-1);
        return sb.toString();
    }

    public static void main(String[] args) {
        String d = resolveParam("b=2&c=3&c=5&", "c");
        System.out.println(d);
    }
}
